<?php
namespace Admin\Controller;
use Common\Controller\CommonController;

class GoodsController extends CommonController {



	public function listAction(){
		$goods = new \Model\GoodsModel();
		$data = $goods->select();
		$this->assign('data',$data);
		$this->display();
	}

	public function addAction(){

		if(!empty($_POST)){

			if($_FILES['goods_image']['error'] < 4){
				$cft = array(
					'rootPath' => './Public/Goods_pic/',
				);

				$up = new \Think\Upload($cft);
				$upInfo = $up->uploadOne($_FILES['goods_image']);
				$big_img  = $up->rootPath.$upInfo['savepath'].$upInfo['savename'];
				$small_img  = $up->rootPath.$upInfo['savepath'].'small_'.$upInfo['savename'];
				//缩略图;
				$im = new \Think\Image();
				$im->open($big_img);
				$im->thumb(40,40);
				$im->save($small_img);


				$_POST['goods_big_img'] = ltrim($big_img,'./');
				$_POST['goods_small_img'] = ltrim($small_img,'./');
				//dump($up->getError());
			}

			$goods = new \Model\GoodsModel();
			$data = $goods->create(); 

			if($goods->add($data)){
				$this->redirect('Goods/list');
			}

		}else{
			$this->display();
		}
	}

	public function editAction(){
		$this->display();
	}




}




?>